package lock;

import java.util.concurrent.TimeUnit;

public class Demo2 {
    public static void main(String[] args) {
        Phone phone = new Phone();

        new Thread(()->{
           phone.listenMusic();
        }).start();



        new Thread(()->{
            phone.show();
        }).start();
    }
}

class Phone{
    public synchronized void listenMusic(){
        try {
            //线程休息1毫秒
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("听音乐！");
    }

    public synchronized void playGame(){
        System.out.println("玩游戏！");
    }

    public void show(){
        System.out.println("亮屏！");
    }
}
